package com.duoduo.admin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.duoduo.common.core.util.Page;
import com.duoduo.common.core.util.PageRequest;
import com.duoduo.common.core.util.R;
import com.duoduo.admin.api.dto.SysLogDTO;
import com.duoduo.admin.service.SysLogService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("sysLog")
@Tag(name = "sysLog接口", description ="sysLog访问接口")
public class SysLogController {
	
	@Autowired
	private SysLogService sysLogService;
	
	/**
	 * 分页
	 * @param request
	 * @return
	 */
	@PostMapping("page")
	@Operation(summary = "分页")
	public R<Page<SysLogDTO>> page(PageRequest<SysLogDTO> request){
		Page<SysLogDTO> page = sysLogService.page(request.getPage(),request.getPageSize(),request.getParam());
		return R.ok(page);
	}
	/**
	 * 详情
	 * @param id
	 * @return
	 */
	@GetMapping("{id}/get")
	@Operation(summary = "详情")
	public R<SysLogDTO> get(@Parameter(description = "主键id") @PathVariable("id")Long id){
		return R.ok(sysLogService.get(id));
	}
	/**
	 * 创建
	 * @param id
	 * @return
	 */
	@Operation(summary = "创建")
	@PostMapping("create")
	public R<SysLogDTO> create(SysLogDTO request){
		sysLogService.create(request);
		return R.ok();
	}
	/**
	 * 修改
	 * @param id
	 * @return
	 */
	@Operation(summary = "修改")
	@PutMapping("update")
	public R<SysLogDTO> update(SysLogDTO request){
		sysLogService.update(request,request.getId());
		return R.ok();
	}
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@Operation(summary = "删除")
	@DeleteMapping("{id}/delete")
	public R<SysLogDTO> delete(@Parameter(description = "主键id") @PathVariable("id")Long id){
		sysLogService.delete(id);
		return R.ok();
	}
}
